package com.stox.client.ui.javafx.widget.auto;

import java.util.ArrayList;
import java.util.List;

import javafx.scene.layout.VBox;

import com.stox.client.ui.javafx.core.util.CSS;
import com.stox.client.ui.javafx.core.util.UI;
import com.stox.shared.beans.BeanDescriptor;
import com.stox.shared.beans.PropertyDescriptor;

public class BeanAutoUI extends VBox {

	private final List<PropertyAutoUI> propertyAutoUIs = new ArrayList<>();
	
	public BeanAutoUI(BeanDescriptor beanDescriptor) {
		UI.style(this, CSS.beanAutoUI);
		
		for(PropertyDescriptor propertyDescriptor : beanDescriptor.getPropertyDescriptors()){
			try{
				propertyAutoUIs.add(new PropertyAutoUI(propertyDescriptor));
			}catch(UnsupportedOperationException ignored){
				// For now ignore this exception, we will support nested and collections properties in future
			}
		}
		
		getChildren().addAll(propertyAutoUIs);
	}
	
	public void setValue(){
		for(PropertyAutoUI propertyAutoUI : propertyAutoUIs){
			propertyAutoUI.setValue();
		}
	}
	
	
}


